package io.wilson.rabbit.config;

import org.springframework.amqp.core.Queue;
import org.springframework.amqp.rabbit.config.SimpleRabbitListenerContainerFactory;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;

@Configuration
public class RabbitConfig {
    @Resource
    SimpleRabbitListenerContainerFactory rabbitListenerContainerFactory;

    @PostConstruct
    public void init() {
        rabbitListenerContainerFactory.setBatchListener(true);
        rabbitListenerContainerFactory.setConsumerBatchEnabled(true);
    }

/*    @Bean("batchListenerContainer")
    public SimpleRabbitListenerContainerFactory rabbitListenerContainerFactory(ConnectionFactory connectionFactory) {
        SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();
        factory.setConnectionFactory(connectionFactory);
        // 启用批量消费
        factory.setBatchListener(true);
        factory.setConsumerBatchEnabled(true);
        factory.setBatchSize(3);
        // 设置每个消费者预取的消息数量，根据实际情况调整
        // 设置消息转换器，这里使用Jackson JSON转换器
//        factory.setMessageConverter(new Jackson2JsonMessageConverter());
        return factory;
    }*/

}
